package com.example.project.activity.kaishi;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.example.project.R;
//欢迎页面
public class WelcomeActivity extends AppCompatActivity {
    private TextView Time;
    private Boolean back=true; //是否第一次登录
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView( R.layout.activity_welcome);
        initView();
        thread.start();
    }

    private void initView() {
        Time=findViewById(R.id.tv_time);
        Time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                back=false;
                Intent intent=new Intent(WelcomeActivity.this, LoginActivity.class);
                startActivity(intent);
            }
        });
    }

    Thread thread=new Thread(new Runnable() {
        @Override
        public void run() {
            int num=3;
            while (true){
                try {
                    Thread.sleep(1000);
                    Message msg=new Message();
                    msg.arg1=num;
                    handler.sendMessage(msg);
                    if(num==0){
                        break;
                    }
                    num--;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    Handler handler=new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            int i=msg.arg1;
            Time.setText(i+"s 跳过");
            if(i==0 && back){
                Intent intent=new Intent(WelcomeActivity.this, LoginActivity.class);
                startActivity(intent);
            }
        }
    };
}